﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Infrastructure.DynamicProxy
{
    public static class ServiceHelp
    {

        public static IServiceProvider? serviceProvider { get; set; }

        public static void BuildServiceProvider(IServiceCollection serviceCollection)
        {
            //构建容器
            serviceProvider = serviceCollection.BuildServiceProvider();
        }

        public static T GetService<T>(Type serviceType)
        {
            return (T)serviceProvider.GetService(serviceType);
        }

        public static T GetService<T>()
        {
            return serviceProvider.GetService<T>();
        }
    }
}
